/*
 * Copyright (c) $today.year-Now http://www.zxpnet.com All rights reserved.
 */

package com.zxp.security.service.impl;

import com.zxp.security.model.User;
import com.zxp.security.repository.UserRepo;
import com.zxp.security.service.UserServiceI;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

/**
 * @author: shollin
 * @date: 2021/7/4/004 21:17
 */
@Service
public class UserServiceImpl implements UserServiceI {

    @Autowired
    UserRepo userRepo;


    @Override
    public User findByUsernameOrPhone(String username) {
        User user = userRepo.findByUsernameOrPhone(username);

        if(user==null){
            throw new UsernameNotFoundException("没有此用户");
        }
        return user;
    }

    @Override
    public User save(User user) {
        return userRepo.save(user);
    }
}
